package com.fengye.algorithms.leecode;

import java.util.Arrays;

/**
 * @Author fengye
 * @Date 2023/4/10 9:34
 **/
public class LargestPerimeter976 {
    public int largestPerimeter(int[] nums) {
        Arrays.sort(nums);
        int a = nums[nums.length - 1];
        int b = nums[nums.length-2];
        for(int i=nums.length - 3; i>=0;i--) {
            int c = nums[i];
            if(a < b + c) {
                return a+b+c;
            } else {
                a = b;
                b = c;
            }
        }
        return 0;
    }
}
